package nl.haemers.data.reflection 
{
	import flash.utils.Dictionary;
	import nl.haemers.data.collections.List;
	import nl.haemers.data.constants.ReflectionConstants;
	import nl.haemers.data.reflection.IMethod;
	
	/**
	 * ...
	 * @author Jonathan Haemers
	 */
	public class Methods implements IMethods 
	{
		private const _RESERVED_METHODS:Vector.<String> = new <String>["hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "setPropertyIsEnumerable", "toLocaleString", "toString", "valueOf"];
		private var _list					:List;
		
		public function Methods(description:XML)
		{
			_list = new List();
			init(description);
		}
		
		/** Public methods **/
		public function getMethod(name:String) : IMethod 
		{
			return _list.search(name) as IMethod;
		}
		
		public function hasMethod(name:String) : Boolean 
		{
			return _list.hasKey(name);
		}
		
		public function getMethods() : Dictionary
		{
			return _list.items;
		}
		
		/* Static methods */
		private function init(xml:XML) : void //Boolean
		{
			//var methods:Methods = new Methods();
			for each(var node:XML in xml.elements(ReflectionConstants.XML_METHOD))
			{
				var method:Method = new Method(node);
				
				_list.overwriteAble = isMethodReserved(method.toString());
				_list.add(method.toString(), method);
			}
			
			//return true;
		}
		
		private function isMethodReserved(name:String) : Boolean
		{
			for each(var methodName:String in _RESERVED_METHODS)
			{
				if (methodName == name)
					return true;
			}
			
			return false;
		}
		
		/** Getters & Setters **/
		
		/** Protected methods **/
		
		/** Private methods **/
		
	}

}